package com.cskaoyan.controller;

import com.cskaoyan.bean.data.PageData;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.FootprintService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {
    @Autowired
    FootprintService footprintService;


    //足迹列表
    @GetMapping("list")
    public BaseRespVo list(Integer page, Integer limit)
    {
        Subject subject = SecurityUtils.getSubject();
        //如果登录
        if(subject.isAuthenticated()){
            Integer userId = (Integer) subject.getPrincipal();
            PageData data =footprintService.list(userId,page,limit);
            return BaseRespVo.ok(data);
        }else{
            return BaseRespVo.unAuthc();
        }
    }

    //足迹删除
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Map map)//直接接收的参数是Json字符串，需要整体转换为map形式来接收
    {
        Integer id = (Integer) map.get("id");
        //此时为登录的情况下，无需判断
         footprintService.delete(id);
         return BaseRespVo.ok(null);
    }

}
